var msgTimer = null;
// import {
// 	siteroot
// } from "@/siteinfo.js";

export const message = (title, duration = 3000, mask = false, icon = 'none') => {
	//统一提示方便全局修改
	if (Boolean(title) === false) {
		return;
	}
	uni.hideToast();
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
	if (msgTimer) {
		clearTimeout(msgTimer)
	}
	msgTimer = setTimeout(function() {
		uni.hideToast();
	}, duration)
}
/**
 * @description 选择图片(相机/相册) 返回不带域名的地址
 * @param {Number}  = [count] 选择数量
 * 
*/ 
export const choolImage = function(count = 1) {
	return new Promise((resolve) => {
		uni.chooseImage({
			count: count || 1,
			sizeType: ['original', 'compressed'],
			sourceType: ['album', 'camera'],
			success: async function(res) {
				let tempFilePaths = res.tempFilePaths,
					imageUrls = [];
				for (let i = 0; i < tempFilePaths.length; i++) {
					imageUrls.push('');
					let result=await uploadImage(tempFilePaths[i]);
					if(result){
						imageUrls[i] = result;
					}
				}
				resolve(imageUrls)
			},
			fail: function(res) { //alert(res.errMsg);
				resolve(false)
			}
		});
	})
}
/**
 * @description 上传图片
 * @@param {String}  = [tempFilePath] 上传文件地址(可为本地地址、网络地址)
 * 
*/ 

export const uploadImage = function(tempFilePath = "") {
	return new Promise((resolve) => {
		uni.showLoading('上传中');
		uni.uploadFile({
			// url: "https://sjms.cskx666.com/api/pdmd/uploadImg",
			// filePath: tempFilePath,
			// name: 'file',
			// success: function(res) {
			// 	var data=null;
			// 	if (typeof res.data == 'string') {
			// 		data = JSON.parse(res.data);
			// 	} else {
			// 		data = res.data;
			// 	}
			// 	if (data.code == 1) {
			// 		uni.hideLoading()
			// 		resolve(data.data.url);//返回结果
			// 	} else {
			// 		message(res.msg||'上传失败');
			// 		resolve(false)
			// 	}
			// },
			// fail: function(res) {
			// 	message('上传发生错误')
			// 	resolve(false)
			// }
		});


	})
}
